package com.mos.base.action;

import com.mos.base.Globl;
import com.mos.entity.User;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * Package Name: com.mos.base.action
 * User: grq
 * Date: 2016/4/5
 * Time: 16:26
 * Description:some des here!
 */
public class BaseAction {

    protected User getNowUser(HttpSession session) {
        return (User) session.getAttribute(Globl.SESSION_USER_KEY);
    }

    protected String getNowUserId(HttpSession session) {
        User user = getNowUser(session);
        String userId ;
        if(user == null) userId = Globl.SYSTEM_ID;
        else userId = user.getId();
        return userId;
    }

    /**
     * 构造流视图
     */
    protected ModelAndView createStreamViewOnly(byte[] bytes){
        ModelAndView mav=new ModelAndView();
        mav.setViewName(Globl.STREAM_VIEW_NAME);
        mav.addObject(Globl.STREAM_DATA_KEY,bytes);
        return mav;
    }

   /* protected ModelAndView createDownloadViewOnly(byte[] bytes,String filename){
        ModelAndView mav=new ModelAndView();
        mav.setViewName(Constants.DOWNLOAD_VIEW_NAME);
        mav.addObject(Constants.DOWNLOAD_DATA_KEY,bytes);
        mav.addObject(Constants.DOWNLOAD_FILENAME_KEY,filename);
        return mav;
    }*/

    /*protected String getBasePath(HttpServletRequest request){
        String path = request.getContextPath();
        String basePath = request.getScheme() + "://"+ request.getServerName() + ":" + request.getServerPort()+ path + "/";
        return basePath;
    }*/
}
